package com.eaoa.uc.customer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.PubPermissionConstants;
import com.eaoa.query.pub.PubCustomerQuery;
import com.eaoa.uc.customer.form.CustomerCondition;
import com.eaoa.uc.customer.form.CustomerSearchForm;
import com.stony.core.util.CoreUtils;

public class CustomerManageSearchAction extends EABaseAction{

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		CustomerSearchForm sform = (CustomerSearchForm) form;
		sform.initConditionPost();
		CustomerCondition condition = (CustomerCondition) sform.getCondition();
		
		PubCustomerQuery query = new PubCustomerQuery();
		if(hasPermission(request, PubPermissionConstants.PERMISSION_PUBCUSTOMER_QUERYALL)){
		}else{
			query.setCustomerno(getEmployee(request).getCustomerids());
		}
		query.setCustomercode(condition.getCustomercode());
		query.setCustomertype(condition.getCustomertype());
		query.setCustomercnname(condition.getName());
		query.setRouteno(CoreUtils.parseLong(condition.getRouteno()));
		query.setIslock("N");
		query.setPageRange(sform.getPageinfo());
		query.execute();
		
		request.setAttribute("results", query.getResults());
		
		return mapping.findForward("success");
	}
}
